home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / e33el2.zip / emacs / 19.33 / lisp / edt-mapper.el < prev    next >
Lisp/Scheme  |  1996-01-20  |  14KB  |  406 lines

  1. ;;; edt-mapper.el --- Create an EDT LK-201 Map File for X-Windows Emacs
  2.  
  3. ;; Copyright (C) 1994, 1995  Free Software Foundation, Inc.
  4.  
  5. ;; Author: Kevin Gallagher <kgallagh@spd.dsccc.com>
  6. ;; Maintainer: Kevin Gallagher <kgallagh@spd.dsccc.com>
  7. ;; Keywords: emulations
  8.  
  9. ;; This file is part of GNU Emacs.
  10.  
  11. ;; GNU Emacs is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ;; GNU General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;;  This emacs lisp program can be used to create an emacs lisp file
  29. ;;  that defines the mapping of the user's keyboard under X-Windows to
  30. ;;  the LK-201 keyboard function keys and keypad keys (around which
  31. ;;  EDT has been designed).  Please read the "Usage" AND "Known
  32. ;;  Problems" sections before attempting to run this program.  (The
  33. ;;  design of this file, edt-mapper.el, was heavily influenced by
  34. ;;  tpu-mapper.el.) 
  35.  
  36. ;;; Usage:
  37.  
  38. ;;  Simply load this file into the X-Windows version of emacs (version 19)
  39. ;;  using the following command.
  40.  
  41. ;;    emacs -q -l edt-mapper.el
  42.  
  43. ;;  The "-q" option prevents loading of your .emacs file (commands therein
  44. ;;  might confuse this program).
  45.  
  46. ;;  An instruction screen showing the typical LK-201 terminal functions keys
  47. ;;  will be displayed, and you will be prompted to press the keys on your
  48. ;;  keyboard which you want to emulate the corresponding LK-201 keys.
  49.  
  50. ;;  Finally, you will be prompted for the name of the file to store
  51. ;;  the key definitions.  If you chose the default, it will be found
  52. ;;  and loaded automatically when the EDT emulation is started.  If
  53. ;;  you specify a different file name, you will need to set the
  54. ;;  variable "edt-xkeys-file" before starting the EDT emulation.
  55. ;;  Here's how you might go about doing that in your .emacs file.
  56.  
  57. ;;    (setq edt-xkeys-file (expand-file-name "~/.my-emacs-x-keys"))
  58.  
  59. ;;; Known Problems:
  60.  
  61. ;;  Sometimes, edt-mapper will ignore a key you press, and just continue to
  62. ;;  prompt for the same key.  This can happen when your window manager sucks
  63. ;;  up the key and doesn't pass it on to emacs, or it could be an emacs bug.
  64. ;;  Either way, there's nothing that edt-mapper can do about it.  You must
  65. ;;  press RETURN, to skip the current key and continue.  Later, you and/or
  66. ;;  your local X guru can try to figure out why the key is being ignored.
  67.  
  68. ;; ====================================================================
  69.  
  70. ;;;
  71. ;;;  Make sure we're running X-windows and Emacs version 19
  72. ;;;
  73. (cond
  74.  ((not (and window-system (not (string-lessp emacs-version "19"))))
  75.   (insert "
  76.  
  77.     Whoa!  This isn't going to work...
  78.  
  79.     You must run edt-mapper.el under X-windows and Emacs version 19.
  80.  
  81.     Press any key to exit.  ")
  82.   (sit-for 600)
  83.   (kill-emacs t)))
  84.  
  85.  
  86. ;;;
  87. ;;;  Decide whether we're running GNU or Lucid emacs.
  88. ;;;
  89. (defconst edt-lucid-emacs19-p (string-match "Lucid" emacs-version)
  90.   "Non-NIL if we are running Lucid Emacs version 19.")
  91.  
  92.  
  93. ;;;
  94. ;;;  Key variables
  95. ;;;
  96. (defvar edt-key nil)
  97. (defvar edt-enter nil)
  98. (defvar edt-return nil)
  99. (defvar edt-key-seq nil)
  100. (defvar edt-enter-seq nil)
  101. (defvar edt-return-seq nil)
  102.  
  103.  
  104. ;;;
  105. ;;;  Make sure the window is big enough to display the instructions
  106. ;;;
  107. (if edt-lucid-emacs19-p (set-screen-size nil 80 36)
  108.   (set-frame-size (selected-frame) 80 36))
  109.  
  110.  
  111. ;;;
  112. ;;;  Create buffers - Directions and Keys
  113. ;;;
  114. (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
  115. (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
  116.  
  117. ;;;
  118. ;;;  Put header in the Keys buffer
  119. ;;;
  120. (set-buffer "Keys")
  121. (insert "\
  122. ;;
  123. ;;  Key definitions for the EDT emulation within GNU Emacs
  124. ;;
  125.  
  126. (defconst *EDT-keys*
  127.   '(
  128. ")
  129.  
  130. ;;;
  131. ;;;   Display directions
  132. ;;;
  133. (switch-to-buffer "Directions")
  134. (insert "
  135.                                   EDT MAPPER
  136.  
  137.     You will be asked to press keys to create a custom mapping (under
  138.     X-Windows) of your keypad keys and function keys so that they can emulate
  139.     the LK-201 keypad and function keys or the subset of keys found on a 
  140.     VT-100 series terminal keyboard.  (The LK-201 keyboard is the standard
  141.     keyboard attached to VT-200 series terminals, and above.)  
  142.  
  143.     Sometimes, edt-mapper will ignore a key you press, and just continue to
  144.     prompt for the same key.  This can happen when your window manager sucks
  145.     up the key and doesn't pass it on to emacs, or it could be an emacs bug.
  146.     Either way, there's nothing that edt-mapper can do about it.  You must
  147.     press RETURN, to skip the current key and continue.  Later, you and/or
  148.     your local X guru can try to figure out why the key is being ignored.
  149.  
  150.     Start by pressing the RETURN key, and continue by pressing the keys
  151.     specified in the mini-buffer.  If you want to entirely omit a key, 
  152.     because your keyboard does not have a corresponding key, for example, 
  153.     just press RETURN at the prompt.
  154.  
  155. ")
  156. (delete-other-windows)
  157.  
  158. ;;;
  159. ;;;  Save <CR> for future reference
  160. ;;;
  161. (cond
  162.  (edt-lucid-emacs19-p
  163.   (setq edt-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
  164.   (setq edt-return (concat "[" (format "%s" (event-key (aref edt-return-seq 0))) "]")))
  165.  (t
  166.   (message "Hit carriage-return <CR> to continue ")
  167.   (setq edt-return-seq (read-event))
  168.   (setq edt-return (concat "[" (format "%s" edt-return-seq) "]")))) 
  169.  
  170. ;;;
  171. ;;;   Display Keypad Diagram and Begin Prompting for Keys
  172. ;;;
  173. (set-buffer "Directions")
  174. (delete-region (point-min) (point-max))
  175. (insert "
  176.  
  177.  
  178.  
  179.           PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
  180.  
  181.  
  182.  
  183.  
  184.     Here's a picture of the standard LK-201 keypad for reference:
  185.  
  186.           _______________________    _______________________________
  187.          | HELP  |      DO       |  |  F17  |  F18  |  F19  |  F20  |
  188.          |       |               |  |       |       |       |       |
  189.          |_______|_______________|  |_______|_______|_______|_______|
  190.           _______________________    _______________________________
  191.          | FIND  |INSERT |REMOVE |  |  PF1  |  PF2  |  PF3  |  PF4  |
  192.          |       |       |       |  |       |       |       |       |
  193.          |_______|_______|_______|  |_______|_______|_______|_______|
  194.          |SELECT |PREVIOU| NEXT  |  |  KP7  |  KP8  |  KP9  |  KP-  |
  195.          |       |       |       |  |       |       |       |       |
  196.          |_______|_______|_______|  |_______|_______|_______|_______|
  197.                  |   UP  |          |  KP4  |  KP5  |  KP6  |  KP,  |
  198.                  |       |          |       |       |       |       |
  199.           _______|_______|_______   |_______|_______|_______|_______|
  200.          |  LEFT |  DOWN | RIGHT |  |  KP1  |  KP2  |  KP3  |       |
  201.          |       |       |       |  |       |       |       |       |
  202.          |_______|_______|_______|  |_______|_______|_______|  KPE  |
  203.                                     |      KP0      |  KPP  |       |
  204.                                     |               |       |       |
  205.                                     |_______________|_______|_______|
  206.  
  207. ")
  208.  
  209. ;;;
  210. ;;;  Key mapping functions
  211. ;;;
  212. (defun edt-lucid-map-key (ident descrip func gold-func)
  213.   (interactive)
  214.   (setq edt-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
  215.   (setq edt-key (concat "[" (format "%s" (event-key (aref edt-key-seq 0))) "]"))
  216.   (cond ((not (equal edt-key edt-return))
  217.      (set-buffer "Keys")
  218.      (insert (format "    (\"%s\" . %s)\n" ident edt-key))
  219.      (set-buffer "Directions"))
  220.     ;; bogosity to get next prompt to come up, if the user hits <C